package com.qiaodata.datatrans.utils;

import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class ReadTxtUtil {

    public static List<String> readTxtFile(String filePath){
        try {
            String encoding="UTF8";
            List<String> list = new ArrayList<String>();
            File file=new File(filePath);
            if(file.isFile() && file.exists()){ //判断文件是否存在
                InputStreamReader read = new InputStreamReader(
                        new FileInputStream(file),encoding);//考虑到编码格式
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                while((lineTxt = bufferedReader.readLine()) != null){
//                        System.out.println(lineTxt);//输出测试
                    list.add(lineTxt);
                }
                read.close();
                return list;
            }else{
                System.out.println("找不到指定的文件");
            }
        } catch (Exception e) {
            System.out.println("读取文件内容出错");
            e.printStackTrace();
        }
        return null;

    }

	 public static void main(String argv[]) throws IOException {
//	        String filePath = "d:\\data\\objids.txt";
////	      "res/";
//	        readTxtFile(filePath);
//         String filePATH = this.getClass().getClassLoader().getResource("/").getPath()+"quanzhiAreas.txt";
//         List<String> lines = IOUtils.readLines(new FileInputStream(filePATH));
//         for (String lin : lines) {
//             String str = lin;
//             System.out.println(str);
//         }
//         ClassPathResource resource = new ClassPathResource("resource/quanzhiAreas.txt");

	    }
}
